<!DOCTYPE html>
<html data-layout-decorate="~{fragment/layout}">
<head>
<meta charset="UTF-8">
<title>添加课程</title>
<link rel="stylesheet" data-th-href="@{../static/bootstrap/css/bootstrap-theme.css}">
<link rel="stylesheet" data-th-href="@{../webjars/bootstrapvalidator/css/bootstrapValidator.css}"/>
<link rel="stylesheet" data-th-href="@{../webjars/bootstrap-select/2.0.0-beta1/dist/css/bootstrap-select.css}">
<link data-th-href="@{../webjars/bootstrapvalidator/css/bootstrapValidator.css}"	rel="stylesheet" />
<script type="text/javascript" 	data-th-src="@{../webjars/bootstrap-select/2.0.0-beta1/dist/js/bootstrap-select.js}"></script>
<script type="text/javascript" data-th-src="@{../webjars/bootstrap-select/2.0.0-beta1/dist/js/i18n/defaults-zh_CN.js}"></script>
<script	data-th-src="@{../webjars/bootstrapvalidator/js/bootstrapValidator.js}"></script>
<script data-th-src="@{../webjars/bootbox/4.4.0/bootbox.js}"></script>

<script type="text/javascript">
	$(function(){
		$("#years").selectpicker({
			title : '选择年级'
		});
		$("#coll").selectpicker({
			title : '选择学院'
		});
		$("#profesion").selectpicker({
			title : '选择专业'
		});
	});
	
	function yearss(year,collegeVal,profesionVal) {
		$.post('findSchoolYear', {
			year : year
		}, function(data) {
			if (data.leangth == 0) {
				bootbox.alert('此年份的学年学期为空数据！请添加学年学期后操作');
			}
			for (var i = 0; i < data.length; i++) {
				$('#xnxq').append(
						"<option value=" + data[i].xnxq + "> " + data[i].xnxq
								+ "</option>");
			}
			var xnxq = '[[${model==null?'':model.xnxq}]]';
			$('#xnxq').selectpicker('val', xnxq);
			$('#xnxq').selectpicker('refresh');
		});
		
		$.post('getCollege', {
			year : year
		}, function(result) {
				$('#coll,#profesion').html(
						'<option style="display: none"></option>');

				for (var i = 0; i < result.length; i++) {
					$('#coll').append(
							"<option value='"+result[i]+"'>" + result[i]
									+ "</option>");
				}
				$('#coll').selectpicker('refresh');
				$('#profesion').selectpicker('refresh');
				if(collegeVal!=null&&collegeVal!=undefined){
					$('#coll').selectpicker('val',collegeVal);
					selectCollege(collegeVal,profesionVal);
					
				}
		})
	}
	
	function selectCollege(college,profesionVal) {
		var year = $('#years').val();
		$.post('../curriculum/getProfesion', {
			college : college,
			year : year
		},
				function(result) {
						$('#profesion').html(
								'<option style="display: none"></option>');
						for (var i = 0; i < result.length; i++) {
							$('#profesion').append(
									"<option value='"+result[i]+"'>"
											+ result[i] + "</option>");
						}
						$('#profesion').selectpicker('refresh');
						if(profesionVal!=null&&profesionVal!=undefined){
							$('#profesion').selectpicker('val',profesionVal);
						}
				})
	}
	
</script>
<style type="text/css">
	.g_home{
		width: 90%;
		margin: 0px auto;
		margin-top: 75px;
		padding: 15px 20px;
		background:white;
		border-radius: 15px;
		overflow:auto;
	}
	body{
		background: url(../static/img/beijing.jpg);
	}
	.g_head{
		padding: 5px 10px;
		color: coral;
		margin-bottom: 10px;
		font-size: 16px;
		position: fixed;
		z-index:3;
	}
</style>
</head>
<body>
<section layout:fragment="content">
	<div class = "g_home" id = "g_home">
		<div class="g_head">
			<a data-toggle="modal" class="btn btn-sm btn-primary" data-target="#myModal">录入课表</a>
		</div>
		<hr style="margin-top: 40px;" />		
		<div class = "g_content">
			<div class="g_kc" th:if="${kc.size() != 0}">
				<table class="table table-hover table-bordered ">
					<tr>
						<th>课程名称</th>
						<th>班级</th>
						<th>老师</th>
						<th>周次</th>
						<th>星期</th>
						<th>节次</th>
						<th>地点</th>
						<th>年级</th>
						<th>专业</th>
					</tr>
					<tr th:each = "c:${kc}">
						<td th:text="${c.kcmc}"></td>
						<td th:text="${c.tbclass}"></td>
						<td th:text="${c.teacher}"></td>
						<td th:text="${c.qszc}"></td>
						<td th:text="${c.xq}"></td>
						<td th:text="${c.jcsj}"></td>
						<td th:text="${c.serialNumber}"></td>
						<td th:text="${c.profession.year}"></td>
						<td th:text="${c.profession.profesion}"></td>
					</tr>
				</table>
			</div>
			
			<center th:if="${kc.size() == 0}"><img width="50%" src="../static/img/h1.jpg" /></center>
		</div>
	</div>
	
	<form id="formEdit" action="save" class="form-horizontal" role="form">
		<div id="myModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
	        <div class="modal-dialog  modal-lg" role="document">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal"
							aria-label="Close">
							<span aria-hidden="true">&times;</span>
						</button>
						<h2 class="modal-title" id="myModalLabel">录入课程</h2>
					</div>
					
	               	<div class="modal-body">
		           		
		           		<div class="row">
							<div class="form-group col-sm-4">
								<label for="year" class="col-sm-5 control-label"><span
									class="text-red">*</span>年级</label>
								<div class="col-sm-7">
									<select id="years" name="year" class="form-control"
										onchange="yearss(this.value)">
										<option style="display: none"></option>
										<option data-th-each="years:${years}" data-th-text="${years}"
											data-th-value="${years}">1</option>
									</select>
								</div>
							</div>
							<div class="form-group col-sm-4">
								<label for="txt_college" class="col-sm-5 control-label"><span
									class="text-red">*</span>学院</label>
								<div class="col-sm-7">
									<select class="form-control" id="coll" name="college"
										onchange="selectCollege(this.value)">
										<option style="display: none"></option>
									</select>
								</div>
							</div>
							<div class="form-group col-sm-4">
								<label for="profesion" class="col-sm-5 control-label"><span
									class="text-red">*</span>专业</label>
								<div class="col-sm-7">
									<select id="profesion" name="profesion"
										onchange="getBanji()" class="form-control">
										<option style="display: none"></option>
									</select>
								</div>
							</div>
							<!-- 	 -->
						</div>
						<div class="row">
							<div class="form-group col-sm-4">
								<label for="xnxq" class="col-sm-5 control-label"><span
									class="text-red">*</span>学年学期</label>
								<div class="col-sm-7">
									<select id="xnxq" name="xnxq" onchange="getkcjhandxq(this.value)"
										class="form-control">
										<option style="display: none"></option>
									</select>
								</div>
							</div>
		
							<div class="form-group col-sm-4">
								<label for="kcjh" class="col-sm-5 control-label"><span
									class="text-red">*</span>课程计划</label>
								<div class="col-sm-7">
									<select id="kcjh" name="kcjhid" class="form-control"
										onchange="setEp()">
										<option style="display: none"></option>
									</select>
								</div>
							</div>
							<div class="form-group col-sm-4">
								<label for="classroom" class="col-sm-5 control-label"><span
									class="text-red">*</span>上课教室</label>
								<div class="col-sm-7">
									<select id="classroom" name="serialNumber" class="form-control"
										data-live-search="true">
										<option style="display: none"></option>
									</select>
								</div>
							</div>
		
						</div>
		
						<div class="row">
							<div class="form-group col-sm-4">
								<label for="skxq" class="col-sm-5 control-label"><span
									class="text-red">*</span>上课星期</label>
								<div class="col-sm-7">
									<select id="skxq" name="skxq" class="form-control"
										onchange="selectSkxq(this.value)">
										<option style="display: none"></option>
										<option data-th-each="jcb:${xq}" data-th-text="${jcb}">1</option>
									</select>
								</div>
							</div>
							<div class="form-group col-sm-4">
								<label for="skjc" class="col-sm-5 control-label"><span
									class="text-red">*</span>上课节次</label>
								<div class="col-sm-7">
									<select id="skjc" name="skjc" class="form-control">
										<option style="display: none"></option>
									</select>
								</div>
							</div>
		
							<div class="form-group col-sm-4">
								<label for="txt_college" class="col-sm-5 control-label"><span
									class="text-red">*</span>选择班级</label>
								<div class="col-sm-7">
									<select id="skbj" name="skbj" class="form-control"
										data-live-search="false" multiple="multiple">
									</select>
								</div>
							</div>
		
		
						</div>
		
		
						<div class="row">
		
							<div class="form-group col-sm-4">
								<label for="text-kcmc" class="col-sm-5 control-label"><span
									class="text-red">*</span>课程名称</label>
								<div class="col-sm-7">
									<input id="kcmc" name="kcmc" class="form-control"
										data-th-value="${model==null?null:model.kcmc}">
								</div>
							</div>
							<div class="form-group col-sm-4">
								<label for="text-teacher" class="col-sm-5 control-label"><span
									class="text-red">*</span>老师</label>
								<div class="col-sm-7">
									<input id="teacher" name="teacher" class="form-control"
										data-th-value="${model==null?null:model.teacher}">
								</div>
							</div>
							<div class="form-group col-sm-4">
								<label for="text-qszc" class="col-sm-5 control-label"><span
									class="text-red">*</span>总学时</label>
								<div class="col-sm-7">
									<input id="qszc" name="zongxs" class="form-control"
										data-th-value="${model==null?null:model.zongxs}">
								</div>
							</div>
		
		
						</div>
		
						<div class="row">
							<div class="form-group col-sm-4">
								<label for="text-qszc" class="col-sm-5 control-label"><span
									class="text-red">*</span>起始周次</label>
								<div class="col-sm-7">
									<input id="qszc" name="qszc" class="form-control"
										data-th-value="${model==null?null:model.qszc}">
								</div>
							</div>
							<div class="form-group col-sm-4">
								<label for="text-jszc" class="col-sm-5 control-label"><span
									class="text-red">*</span>结束周次</label>
								<div class="col-sm-7">
									<input id="jszc" name="jszc" class="form-control"
										data-th-value="${model==null?null:model.jszc}">
								</div>
							</div>
		
							<div class="form-group col-sm-4">
								<label for="txt_kclb" class="col-sm-5 control-label"><span
									class="text-red">*</span>课程类别</label>
								<div class="col-sm-7">
									<select id="lbSelect" class="selectpicker form-control"
										data-live-search="false" multiple="multiple" name="kclb"
										data-max-options="2" data-min-options="2">
										<option data-th-each="c:${courseCategorys}"
											data-th-value="${c.type}" data-th-text="${c.type}">类别1</option>
									</select>
								</div>
							</div>
		
		
						</div>
						<div class="row">
							<div class="form-group col-sm-4">
								<label for="txt_college" class="col-sm-5 control-label"><span
									class="text-red">*</span>项目化</label>
								<div class="col-sm-7">
									<select id="xmh" name="xmh" class="form-control">
										<option style="display: none"></option>
										<option value="true"
											data-th-selected="${model==null?null:model.xmh!=null&&model.xmh}">是</option>
										<option value="false"
											data-th-selected="${model==null?null:model.xmh==null||!model.xmh}">否</option>
									</select>
								</div>
							</div>
							<div class="form-group col-sm-4">
								<label for="txt_kkxq" class="col-sm-5 control-label"><span
									class="text-red">*</span>开课学期</label>
								<div class="col-sm-7">
									<select name="kkxq" class="form-control" id="kkxq">
										<option style="display: none"></option>
										<option value="一">一</option>
										<option value="二">二</option>
										<option value="三">三</option>
										<option value="四">四</option>
										<option value="五">五</option>
										<option value="六">六</option>
									</select>
								</div>
							</div>
						</div>
		
					</div>
						
					<div class="modal-footer">
		                <button type="submit" class="btn btn-primary">
		                	<span class="glyphicon glyphicon-floppy-disk" aria-hidden="true"></span>保存
		                </button>
		                <button type="button" class="btn btn-danger" data-dismiss="modal">
							<span class="glyphicon glyphicon-remove"></span> 关闭
						</button>
		           	</div>
	            </div>
	            
	       	</div>
		</div>
	</form>

<script type="text/javascript">
	bootbox.setDefaults({
		locale:'zh_CN',
		size: 'small',
		title:'提示'
	});
	$("#classroom").selectpicker({
		title : '选择教室'
	});
	
	$("#skjc").selectpicker({
		title : '选择节次'
	});

	$("#xnxq").selectpicker({
		title : '选择学年学期'
	});
	$("#skxq").selectpicker({
		title : '选择上课星期'
	});
	$("#kcjh").selectpicker({
		title : '选择课程计划'
	});

	$("#skbj").selectpicker({
		title : '选择班级'
	});
	$("#xmh").selectpicker({
		title : '是否项目化'
	});
	$("#lbSelect").selectpicker({
		title : '选择课程类别'
	});
	$("#kkxq").selectpicker({
		title : '选择开课学期'
	});
	
	$(function() {
		//设置页面
		var a = window.innerHeight - 150 + "px";
		$("#g_home").css('height', a);

		$.post('classroom', function(data) {
			if (data.length == 0) {
				bootbox.alert('没有教室！请添加后操作');
			}
			for (var i = 0; i < data.length; i++) {
				$('#classroom').append(
						"<option value=" + data[i].serialNumber + "> "
								+ data[i].serialNumber + "</option>");

			}
			var js = '[[${model==null?'':model.serialNumber}]]';
			$('#classroom').selectpicker('val', js);

			$('#classroom').selectpicker('refresh');
		});
	});
	
	
	var options = {
		excluded : [':disabled'],
		message : '验证不通过',
		feedbackIcons : {
			valid : 'glyphicon glyphicon-ok',
			invalid : 'glyphicon glyphicon-remove',
			validating : 'glyphicon glyphicon-refresh'
		},
		fields : {
			college : {
				validators : {
					notEmpty : {
						message : '学院不能为空'
					}
				}
			},
			profesion : {
				validators : {
					notEmpty : {
						message : '专业不能为空'
					}
				}
			},
			xnxq : {
				validators : {
					notEmpty : {
						message : '学年学期不能为空'
					}
				}
			},
			serialNumber: {
				validators : {
					notEmpty : {
						message : '教室不能为空'
					}
				}
			},
			skxq: {
				validators : {
					notEmpty : {
						message : '上课星期不能为空'
					}
				}
			},
			skjc: {
				validators : {
					notEmpty : {
						message : '上课节次不能为空'
					}
				}
			},
			skbj: {
				validators : {
					notEmpty : {
						message : '上课班级不能为空'
					}
				}
			},
			kcmc: {
				validators : {
					notEmpty : {
						message : '课程名称不能为空'
					}
				}
			},
			teacher: {
				validators : {
					notEmpty : {
						message : '教师不能为空'
					}
				}
			},
			zongxs: {
				validators : {
					notEmpty : {
						message : '总学时不能为空'
					}
				}
			},
			qszc: {
				validators : {
					notEmpty : {
						message : '起始周次不能为空'
					}
				}
			},
			jszc: {
				validators : {
					notEmpty : {
						message : '结束周次不能为空'
					}
				}
			},
			kclb: {
				validators : {
					notEmpty : {
						message : '课程类别不能为空'
					}
				}
			},
			kkxq: {
				validators : {
					notEmpty : {
						message : '开课学期不能为空'
					}
				}
			}
		}
	};
	 $('#formEdit').bootstrapValidator(options).on('success.form.bv', function(e) {
				e.preventDefault(); //很重要没有它则会提交默认表单，不会做下面的ajax表单提交
				var fd = new FormData($("#formEdit")[0]);
				$.ajax({
					url : "save1",
					type : "post",
					data : fd,
					processData : false, // 不处理数据  
					contentType : false, // 不设置内容类型
					success : function(result) {
						bootbox.confirm({
							title:'<span class="glyphicon glyphicon-question-sign"></span> 提示信息',
							message: '<h4>'+result.msg+'</h4>',
							buttons: {
					            cancel: {
					                label: '<i class="glyphicon glyphicon-remove"></i> 取消'
					            },
					            confirm: {
					                label: '<i class="glyphicon glyphicon-ok"></i> 确定'
					            }
					        },
					        callback: function (result) {
					        	window.location.href="tjkc";
					        }
						});
						
					},
					error : function(result) {
						alert(result);
						window.location.href="tjkc";
					}
				});
			});

	 function selectSkxq(skxq, skjcval) {
		$.post('getSkjc', {
			skxq : skxq
		}, function(result) {
			$('#skjc').html('<option style="display: none"></option>');
			for (var i = 0; i < result.length; i++) {
				$('#skjc').append(
						"<option value='"+result[i].jcsj+"'>" + result[i].jcsj
								+ "</option>");
			}
			var skjc = '[[${model==null?'':model.jcsj}]]';
			$('#skjc').selectpicker('val', skjc);
			$('#skjc').selectpicker('refresh');

		})

	}

	var skxq='[[${model==null?'':model.jcb.xq}]]';
	$('#skxq').selectpicker('val', skxq);
	selectSkxq(skxq);

	function setEp() {
		var selectEpid = $('#kcjh').val();
		$.post('getEp', function(result) {
			for (var i = 0; i < result.length; i++) {
				if (result[i].id == selectEpid) {
					$('input[name="kcmc"]').val(result[i].curriculum.kcmc);
					$('input[name="teacher"]').val(result[i].teacher.name);
					$('input[name="qszc"]').val(result[i].qszc);
					$('input[name="jszc"]').val(result[i].jszc);
					var skbj=result[i].bj.split(',');
					$('#skbj').selectpicker('val',skbj);
					skbj=null;
					$('input[name="zongxs"]').val(result[i].zongxs);
					$('input[name="xmh"]').val(result[i].xmh);
					var kclb=result[i].kclb.split('/');
					console.log(kclb);
					$('#lbSelect').selectpicker('val',kclb);
					kclbs=null;
				}
			}
		})
	};
	
	function getBanji(year,college,profesion) {
		if(year==null||year==undefined){
			var year=$('#years').val();
		}
		if(college==null||college==undefined){
			var college=$('#coll').val();
		}
		if(profesion==null||profesion==undefined){
			var profesion=$('#profesion').val();
		}
		$.post('getBanji', {
			year:year,
			college:college,
			profesion : profesion
		}, function(result) {
			if (result == null) {
				return;
			}
			$('#skbj').html('<option style="display: none"></option>');
			for (var i = 0; i < result.length; i++) {
				$('#skbj').append(
						"<option value='"+result[i].name+"'>" + result[i].name
								+ "</option>");
			}
			if([[${model!=null}]]){
				var skbj='[[${(model==null||model.tbclass==null)?null:model.tbclass}]]';
				$('#skbj').selectpicker('val',skbj.split(','));
			}
			$('#skbj').selectpicker('refresh');
		})
	}
	

	function getkcjhandxq(xnxq,year,college,profesion) {
		$("#kcjh").html("<option style='display:none;'</option>");
		$('#kcjh').selectpicker('refresh');
		if(year==null||year==undefined){
			var year=$('#years').val();
		}
		if(college==null||college==undefined){
			var college=$('#coll').val();
		}
		if(profesion==null||profesion==undefined){
			var profesion=$('#profesion').val();
		}
		$.post('kcjhandxq1', {
			year:year,
			college:college,
			profesion : profesion,
			schoolyear : xnxq
		}, function(data) {
			if (data.leangth == 0) {
				bootbox.alert('没有课程计划！请添加后操作');
			}
			for (var i = 0; i < data.length; i++) {
				$('#kcjh').append(
						"<option value=" + data[i].id + "> ["
								+ data[i].teacher.name + "]&emsp;"
								+ data[i].kcmc + "</option>");
			}
			$('#kcjh').selectpicker('refresh');
		});
	}
	
	$(window).resize(function() {
		var a = window.innerHeight - 150 + "px";
		$("#g_home").css('height', a);
	});
</script>
</section>
</body>
</html>